package com.shengbo.product.listener;

import com.rabbitmq.client.Channel;
import com.shengbo.product.vo.AttrVo;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@RabbitListener(queues="topic.1.product")
public class ProductListener {

    @RabbitHandler
    public void listen(AttrVo attrVo, Message message, Channel channel) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try{
            //这里的true和false为requeue是否再次加入队列中
            System.out.println(attrVo);
            channel.basicAck(deliveryTag, false);
        }catch (Exception e){
            channel.basicReject(deliveryTag, true);
        }

    }
}
